from selenium.webdriver.common.by import By

from base.page_base import PageBase


class SearchPage(PageBase):
    """搜索页面"""
    # 元素定位
    __search_box = (By.ID, 'com.netease.yanxuan:id/iv_home_search_icon')
    __search_input = (By.ID, 'com.netease.yanxuan:id/search_input')
    __search_btn = (By.ID, 'com.netease.yanxuan:id/tv_search_button')
    __search_res = (By.XPATH, '//android.widget.TextView[@text="【青春系列】100%新疆棉吸水超柔毛巾浴巾"]')
    __search_res_text = (By.XPATH, '//android.widget.TextView[@text="【青春系列】100%新疆棉吸水超柔毛巾浴巾"]')

    # 操作方法
    def click_search_box(self):
        """点击搜索框"""
        self.base_click(self.__search_box)

    def input_search_text(self, text):
        """输入搜索文本"""
        self.base_input_text(self.__search_input, text)
        self.base_click(self.__search_btn)

    def get_search_res(self):
        """获取搜索结果"""
        return self.base_get_text(self.__search_res)

    # 搜索业务流程
    def search(self, text):
        """搜索业务"""
        self.click_search_box()
        self.input_search_text(text)
        return self.get_search_res()

    def get_search_res_text(self):
        """获取搜索结果文本"""
        return self.base_get_text(self.__search_res_text)
